package sort;

import java.util.Arrays;

public class ShellSort {
    public static void main(String[] args) {
        int []array=new int[]{32,12,45,23,12,31,34,15,22};
        int index=1;
        for(int interval=array.length/2;interval>0;interval/=2){
            for(int i=interval;i<array.length;i++){
                int j=i-interval;
                int temp=array[i];
                while(j>-1&&temp<array[j]){
                    //移动
                    array[j+interval]=array[j];
                    j-=interval;
                }
                array[j+=interval]=temp;
            }
            System.out.print("第"+index+"躺排序结果："+ Arrays.toString(array));
            System.out.println();
            index++;
        }
        System.out.print("最终结果：");
        for(int i=0;i<array.length;i++){
            System.out.print(array[i]+" ");
        }
    }
}
